package com.taotao.portal.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.taotao.common.HttpClientUtil;
import com.taotao.common.TaotaoResult;
import com.taotao.portal.pojo.SearchResult;
import com.taotao.portal.service.SearchServer;
@Service
public class SearchServerImpl implements SearchServer {
	@Value("${BASE_URL}")
	private String BASE_URL;
	@Override
	public SearchResult searchItem(String query, int page) {
		Map<String,String> param=new HashMap<>();
		param.put("q", query);
		param.put("page", page+"");
		try {
			String json=HttpClientUtil.doGet(BASE_URL, param);
			TaotaoResult taotaoResult = TaotaoResult.formatToPojo(json, SearchResult.class);
			if(taotaoResult.getStatus()==200){
				return (SearchResult) taotaoResult.getData();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	
		return null;
	}

}
